﻿var _sysaction_Index_dialog;
var _sysaction_index_datagrid;
$(function () {
    _sysaction_index_datagrid = $('#sysaction_index_datagrid').datagrid({
        url: '/SysAction/ListView',
        fit: true,
        fitColumns: "true",
        striped: true,
        columns: [[
        { field: 'SysActionName', title: '名称', width: 50, align: 'center' },
        { field: 'IcoUrl', title: '图标', width: 50, align: 'center' },
        { field: 'State', title: '数据状态', width: 50, align: 'center', formatter: function (value, row, index) {
            if (value) {
                return "启用";
            }
            else {
                return "未启用";
            }
        }
        },
        { field: 'CheckInTime', title: '录入时间', width: 100, align: 'center', formatter: function (value, row, index) {
            return value.FormatTime();
        }
        }, {
            field: 'SysActionID', title: '主键', hidden: true
        }
    ]],
        toolbar: [{
            iconCls: 'icon-add',
            text: '新增',
            handler: function () { sysaction_index_Add(); }
        },{
            iconCls: 'icon-edit',
            text: '修改',
            handler: function () { alert('edit') }
        }, {
            iconCls: 'icon-remove',
            text: '删除',
            handler: function () { module_index_delet(); }
        }],
        pageSize: 10,
        pagination: true,
        pageList: [10, 20, 30, 40, 50],
        border: false
    });
});
function sysaction_index_Add() {
    _sysaction_Index_dialog = parent.sysmain.dialog({
        href: '/SysAction/Add',
        title: '新增',
        height: 230,
        width: 410,
        iconCls: 'icon-save',
        closed: false,
        modal: true,
        buttons: [{
            text: '确定',
            iconCls: 'icon-ok',
            handler: function () {
                var f = _sysaction_Index_dialog.find('form');
                f.form('submit', {
                    url: '/SysAction/Add',
                    success: function (data) {
                        var json = $.parseJSON(data);
                        if (json.Result == true) {
                            parent.sysmain.messagerShow({
                                title: '提示',
                                msg: '数据保存成功'
                            }
                            );
                            _sysaction_index_datagrid.datagrid('reload');
                        }
                    }
                });
            }
        }, {
            text: '取消',
            iconCls: 'icon-no',
            handler: function () {
                _sysaction_Index_dialog.dialog("destroy");
            }
        }]
    });
}
function module_index_delet() {
    var row = _sysaction_index_datagrid.datagrid('getSelected');
    if (row == null) {
        parent.sysmain.messagerAlert('提示', '请选择要删除的数据');
        return;
    } else {
        parent.sysmain.messagerConfirm('提示', '你确定要删除这项数据吗？', function (r) {
            if (r) {

                $.post('/SysAction/Delet', { SysActionID: row.SysActionID }, function (data) {
                    if (data.Result == true) {
                        _sysaction_index_datagrid.datagrid('reload');
                    }
                    else {
                        parent.sysmain.messagerShow({
                            title: '提示',
                            msg: '数据删除失败！'
                        });
                    }
                }
                );


            }
        });

    }
}
